<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="../css/biojs.table.css">
        <script src="../js/vendor/jquery-1.10.2.min.js"></script>
        <script src="../js/jquery.dataTables.min.js"></script>
    </head>
    <body>
         <div id="table"></div>
    </body>
    
    <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
        
          ga('create', 'UA-45417550-1', 'mpg.de');
          ga('send', 'pageview');
        
    </script>
    
    <script type="text/javascript">
        
        $(document).ready(function() {
            var getQueryVariable = function(variable) {
                var query = window.location.search.substring(1);
                var vars = query.split("&");
                for (var i=0;i<vars.length;i++) {
                    var pair = vars[i].split("=");
                    if (pair[0] == variable) {
                        return pair[1];
                    }
                }  
                return null;
            }
            
            //Display the table
            var render_table = function(jobId){
            
                $.ajax({
                    url: 'http://dachstein.biochem.mpg.de:8080/mimerge/download/'+jobId,
                    type: 'GET',
                    success: function (data) {
                                
                        var matrix = [];
                        var tmpArray = data.split('\n');
                        for (var i = 0; i < tmpArray.length; i++) {
                            if(tmpArray[i] != '')
                                matrix.push(tmpArray[i].split('\t'));
                        }
                                
                        var cols = [
                            { "sTitle": "Id A" },
                            { "sTitle": "Id B" },
                            { "sTitle": "Alt Id A" },
                            { "sTitle": "Alt Id B" },
                            { "sTitle": "Aliases A" },
                            { "sTitle": "Aliases B" },
                            { "sTitle": "Detection Methods" },
                            { "sTitle": "Publication" },
                            { "sTitle": "Publication Id" },
                            { "sTitle": "Taxonomy A" },
                            { "sTitle": "Taxonomy B" },
                            { "sTitle": "Interaction Types" },
                            { "sTitle": "Source Databases" },
                            { "sTitle": "Interaction identifiers" },
                            { "sTitle": " Confidence Score" }
                       ];
                                
                        $('#table').html( '<a href="http://dachstein.biochem.mpg.de:8080/mimerge/download/'+jobId+'" download="ClusteredInteractions.tab">Click here to Download</a><table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>' );
                                
                                
                        $('#example').dataTable({
                            "aaData": matrix,
                            "aoColumns": cols,
                            "sScrollY": "100%",
                            "sScrollX": "100%",
                            "sScrollXInner": "110%"
                        });	
                    },
                    error: function (err) {
                        console.log(err);
                    }
                    });
                };
            
                var jobId = getQueryVariable('jobId');
                console.log(jobId);
                render_table(jobId);
        });
        
    </script>
</html>